<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body{
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      flex-direction: column;
      /* 设置行列之间的间距 */
      gap: 30px;
      background-color: #1d2b3a;
    }
    .inputBox{
      position: relative;
      width: 250px;
    }
    .inputBox input{
      width: 100%;
      padding: 10px;
      border: 1px solid rgba(255, 255,255, 0.25);
      background-color: #1d2b3a;
      border-radius: 5px;
      outline: none;
      color: #fff;
      font-size: 1em;
      transition: 0.5s;
    }
    .inputBox span{
      position: absolute;
      left: 0;
      padding: 10px;
      /* 鼠标事件：选中，点击 */
      pointer-events: none;
      font-size: 1em;
      color: rgba(255, 255,255, 0.25);
      /* 转换文字的样式 */
      text-transform: uppercase;
      transition: 0.5s;
    }
    /* 合法输入时的样式：即有输入时的span */
    .inputBox input:valid ~ span,
    .inputBox input:focus ~ span
    {
      color:#00dfc4;
      transform: translateX(10px) translateY(-7px);
      font-size: 0.65em;
      padding: 0 10px;
      background-color: #1d2b3a;
      border-left: 1px solid #00dfc4;
      border-right: 1px solid #00dfc4;
      letter-spacing: 0.2em;
    }
    .inputBox:nth-child(2) input:valid ~ span,
    .inputBox:nth-child(2) input:focus ~ span{
      background: #00dfc4;
      color: #fff;
    }
    .inputBox input:valid ,
    .inputBox input:focus {
      border: 1px solid #00dfc4;
    }
  </style>
</head>
<body>
  <div class="inputBox">
    <input type="text" required="required">
    <span>First Name</span>
  </div>
  <div class="inputBox">
    <input type="text" required="required">
    <span>Last Name</span>
  </div>
</body>
</html>